package cn.software.service.impl;

import cn.software.entity.TopicPaper;
import cn.software.entity.param.PaperParam;
import cn.software.mapper.TopicPaperMapper;
import cn.software.service.TopicPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Service
public class TopicPaperServiceImpl implements TopicPaperService {
    @Autowired
    private TopicPaperMapper topicPaperMapper;


    @Override
    public boolean saveTopicListOfPaper(Integer paperId, PaperParam paperParam) {
        List<Integer> topicIdList = mergeTopicListOfPaper(paperParam);
        int insert = topicPaperMapper.insertBatch(paperId, topicIdList);
        return insert > 0;
    }

    private List<Integer> mergeTopicListOfPaper(PaperParam paperParam) {
        List<Integer> list = new ArrayList<>();
        list.addAll(Arrays.asList(paperParam.getAnswerArr()));
        list.addAll(Arrays.asList(paperParam.getJudgeArr()));
        list.addAll(Arrays.asList(paperParam.getMultiSelectArr()));
        list.addAll(Arrays.asList(paperParam.getSingleSelectArr()));
        return list;
    }
}
